package ui.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fy.fyzf.R;
import com.fy.fyzf.base.BaseActivity;
import com.fy.fyzf.bean.CheckWorkListBean;
import com.fy.fyzf.bean.CommonSearchBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.IsInfoBean;
import com.fy.fyzf.bean.RandomTextBean;
import com.fy.fyzf.bean.WorkStepBean;
import com.fy.fyzf.presenter.CheckWorkPresenter;
import com.fy.fyzf.view.CheckWorkCallBack;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.List;

import butterknife.BindView;
import ui.adapter.CheckWorkRecordAdapter;

public class CheckWorkRecordActivity extends BaseActivity<CheckWorkPresenter> implements CheckWorkCallBack {


    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    @BindView(R.id.smartRefresh)
    SmartRefreshLayout smartRefresh;
    private CheckWorkRecordAdapter checkWorkRecordAdapter;

    @Override
    protected CheckWorkPresenter createPresenter() {
        return new CheckWorkPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_check_work_record;
    }

    private int tag = 1;
    private int page = 1;
    private int pageSize = 10;
    @Override
    public void initView() {
        super.initView();
        setTitleName("考勤记录");
        smartRefresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                tag = 2;
                page++;
                initData();
            }
        });

        smartRefresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                tag = 1;
                page = 1;
                initData();
            }
        });

        checkWorkRecordAdapter = new CheckWorkRecordAdapter();
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        recycleView.setAdapter(checkWorkRecordAdapter);
    }

    private CommonSearchBean commonSearchBean = new CommonSearchBean();
    @Override
    public void initData() {
        super.initData();
        commonSearchBean.setPageSize(pageSize);
        commonSearchBean.setPageNum(page);
        mPresenter.getCheckWorkList(commonSearchBean);
    }

    @Override
    public void CheckWorkSuccess(BaseData baseData) {

    }

    @Override
    public void getCheckWorkListSuccess(CheckWorkListBean checkWorkListBean) {
        smartRefresh.finishLoadMore();
        smartRefresh.finishRefresh();

        if (null == checkWorkListBean ) {
            checkWorkRecordAdapter.setEmptyView(R.layout.layout_nodata_msg);
        }

        if (tag == 1) {
            checkWorkRecordAdapter.setNewData(checkWorkListBean.getList());
        } else {
            checkWorkRecordAdapter.addData(checkWorkListBean.getList());
        }

    }

    @Override
    public void getWorkStepSuccess(WorkStepBean workStepBean) {

    }

    @Override
    public void addWorkLogSuccess(BaseData baseData) {

    }

    @Override
    public void getUserLocationSucccess(RandomTextBean randomTextBean) {

    }

    @Override
    public void isInfoSuccess(IsInfoBean isInfoBean) {

    }


}